//
//  MKTChatMsgButtonListTVCellOther.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/9.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatMsgButtonListTVCellOther.h"
#import "MKTChatLinkCVCell.h"
@implementation MKTChatMsgButtonListTVCellOther
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.buttonCollectionView = [[MKUICollectionFlowLayoutView alloc] initWithFrame:self.bounds];
        
        self.buttonCollectionView.collectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        self.buttonCollectionView.collectionViewFlowLayout.minimumLineSpacing = 10;
        self.buttonCollectionView.collectionViewFlowLayout.minimumInteritemSpacing = 10;
        
        self.buttonCollectionView.scrollEnabled = NO;
        self.buttonCollectionView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.buttonCollectionView];
        //
        MKUIFlowLayoutConstraint *f1 = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.msgTextBubbleView,self.buttonCollectionView] constraintParam:(MKUIFlowLayoutConstraintParam_V_T_L) contentInsets:UIEdgeInsetsZero interitemSpacing:10];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.msgUserPicView,f1] constraintParam:(MKUIFlowLayoutConstraintParam_H_T_L) contentInsets:self.msgTextBubbleLayout.contentInsets interitemSpacing:self.msgTextBubbleLayout.interitemSpacing];
    }
    return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    MKTChatMsgButtonList *msg = self.chatMsg;
    self.msgTextBubbleView.textLabel.text = msg.text;
    [self __reloadButtonCollectionData];
}
- (void)__reloadButtonCollectionData{
    [self.buttonCollectionView.model removeAllSectionModels];
    MKTChatMsgButtonList *msg = self.chatMsg;
    for (MKTChatLink *link in msg.btnlist) {
        MKUICollectionViewCellModel *cm = [[MKUICollectionViewCellModel alloc] init];
        cm.modelValue = link;
        cm.whenClick = ^(MKUICollectionViewCellModel * _Nonnull cellModel) {
            [link handleClick:cellModel.collectionViewCell];
        };
        cm.cellClass = [MKTChatLinkCVCell class];
        [self.buttonCollectionView.model addCellModel:cm];
    }
    [self.buttonCollectionView.model reloadCollectionViewData];
}
- (CGSize)customSizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
@end
